CONTENTS | INDEX | PREV | NEXT
tmpnam
NAME
tmpnam - create a unique, temporary file name
SYNOPSIS
#include <stdio.h>
char *filename = tmpnam(buf);
char *buf;
FUNCTION
tmpnam() creates a unique temporary file name meant to never
be seen by the user. The filename tmpnam() creates will be
no more than L_tmpnam bytes long (L_tmpnam is a macro in <stdio.h>),
including the nul so you can simply declare a buffer:
char buf[L_tmpnam];
tmpnam() returns the buffer into which it created the temporary
file name. If you specify a non-NULL buffer it returns its first
argument.
If you pass NULL to tmpnam() then tmpnam() will use its down internal
static buffer (overwritting any previous name that was stored in
said buffer) and return a pointer to that.
EXAMPLE
#include <stdio.h>
#include <assert.h>
main()
{
char buf[L_tmpnam];
char *ptr;
ptr = tmpnam(NULL);
puts(ptr);
assert(tmpnam(buf) == buf); /* returns argument */
puts(buf);
/* haven't overwritten it yet */
printf("%s (same as first)n", ptr);
assert(tmpnam(NULL) == ptr); /* that will overwrite it! */
puts(ptr);
return(0);
}
INPUTS
char *buf; optional buffer of at least L_tmpnam bytes to
hold the temporary file name or NULL to have
tmpnam() use its own internal buffer.
RESULTS
char *ptr; pointer to buffer (buf if buf != NULL)
SEE ALSO
tmpfile